package com.imaker.action;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.imaker.domain.ModulesInfo;
import com.imaker.domain.Navigation;
import com.imaker.service.ModulesService;
import com.imaker.service.NavigationService;
import com.imaker.utils.Validate;

 /**
 * <p>程序名称：       NavigationAction.java</p>
 * <p>程序说明：       导航栏，包含导航栏的增删改查等</p>
 * <p>版权信息：       Copyright mayonghua</p>
 * <p>时间：          Nov 5, 2010 9:36:50 AM</p>	
 * @author：          mayonghua
 * @version：         Ver 0.1
 */
@Controller
@Scope("prototype")
public class NavigationAction extends BaseAction {

	private static final long serialVersionUID = 1L;
	private Navigation navigation;
	@Autowired
	private ModulesService modulesService;
	private List<ModulesInfo> modulesList;
	private ModulesInfo modulesInfo;
	@Autowired
	private NavigationService navigationService;
	private List<Navigation> navList ;//导航栏菜单列表
	private String flag;
	
	/**
	 * 导航菜单管理页面初始化
	 * @return
	 */
	public String init() throws Exception{
//		查询所有的导航栏
		navList = navigationService.findAll();
		getRequest().setAttribute("navList",navList);
		return SUCCESS;
	}
	
	public String listTree() throws Exception {

		return SUCCESS;
	}
	
	/**
	 * 分页显示导航栏的内容
	 */
	public String listByPage() throws Exception {
		if(Validate.entityNotNull(navigation)){
		page = navigationService.listByPage(page,navigation);
		getRequest().setAttribute("page",page);
		}
		return SUCCESS;
	}
	
	/**
	 * 预新建
	 */
	public String toSave() throws Exception {
		modulesList = modulesService.findAll();
		if(Validate.entityNotNull(navigation)&&!"00000000000000000000000000000000".equals(navigation.getId())){
			navigation = navigationService.findById(navigation.getId());
			return "CHILDREN";
			}else {
			navigation.setPid("00000000000000000000000000000000");
			return "ROOT";
		}
	}
	
	/**
	 * 新建
	 * @return
	 * @throws Exception
	 */
	public String save() throws Exception{ 
		if(Validate.entityNotNull(navigation)){
		navigation.setCreateDate(new Date());
		navigation.setModifyDate(new Date());
		navigationService.save(navigation);
		}
		return SUCCESS;
	}
	
	/**
	 * 预修改
	 * @return
	 * @throws Exception
	 */
	public String toUpdate() throws Exception {
		if(Validate.entityNotNull(navigation))
		navigation = navigationService.findById(navigation.getId());
		modulesList = modulesService.findAll();
		return SUCCESS;
	}
	
	
	/**
	 * 修改
	 * @return
	 * @throws Exception
	 */
	public String update() throws Exception {
		navigationService.update(navigation);
		return SUCCESS;
	}
	
	/**
	 * 删除
	 * @return
	 * @throws Exception
	 */
	public String delete() throws Exception {
		navigationService.delete(idList);
		return SUCCESS;
	}
	
	
	
	public Navigation getNavigation() {
		return navigation;
	}

	public void setNavigation(Navigation navigation) {
		this.navigation = navigation;
	}

	public NavigationService getNavigationService() {
		return navigationService;
	}

	public void setNavigationService(NavigationService navigationService) {
		this.navigationService = navigationService;
	}

	public static long getSerialVersionUID() {
		return serialVersionUID;
	}

	public List<Navigation> getNavList() {
		return navList;
	}

	public void setNavList(List<Navigation> navList) {
		this.navList = navList;
	}

	public String getFlag() {
		return flag;
	}

	public void setFlag(String flag) {
		this.flag = flag;
	}

	public ModulesService getModulesService() {
		return modulesService;
	}

	public void setModulesService(ModulesService modulesService) {
		this.modulesService = modulesService;
	}

	public List<ModulesInfo> getModulesList() {
		return modulesList;
	}

	public void setModulesList(List<ModulesInfo> modulesList) {
		this.modulesList = modulesList;
	}

	public ModulesInfo getModulesInfo() {
		return modulesInfo;
	}

	public void setModulesInfo(ModulesInfo modulesInfo) {
		this.modulesInfo = modulesInfo;
	}
	
}
